<script type="text/javascript">
	
	var code = "1+2+3";
	var index = 0;
	var lookahead = code[index];
	var translateResult = '';
	
	function expr(){
		term();rest();
	}
	function rest(){
		switch(lookahead){
			case '+':
				match('+');term();
				translateResult += "+";
				rest();
				break;
			case '-':
				match('-');term();
				translateResult += "-";
				rest();
				break;
			default:
				break;
		}
	}

	function term(){
		var result = match("number");
		translateResult += ""+result+"";
	}
	
	function match(obj){
		var result = lookahead;
		if(obj == "number"){
			if(/^\d{1}$/.test(lookahead)){
				index++;
				lookahead = code[index];
				return result;
			}
		}else{
			if(lookahead == obj){
				index++;
				lookahead = code[index];
				return result;
			}
		}
		console.log("Syntax error!")
	}
	
	expr();
	console.log(translateResult);
	
	
	
	
	
</script>